import {
  Component,
  Injector,
  ViewEncapsulation,
  ViewChild,
  OnInit,
} from "@angular/core";
import { AppComponentBase } from "@shared/common/app-component-base";
import {
  PipelineServiceProxy,
  TeamGroupTaskServiceProxy,
} from "@shared/service-proxies/service-proxies";
import { appModuleAnimation } from "@shared/animations/routerTransition";
import { Table } from "primeng/components/table/table";
import { Paginator } from "primeng/components/paginator/paginator";
import { LazyLoadEvent } from "primeng/components/common/lazyloadevent";
import { MenuItem } from "primeng/api";
import * as moment from "moment";
@Component({
  templateUrl: "./distributiongang.component.html",
  styleUrls: ["./distributiongang.component.less"],
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()],
})
export class DistributiongangComponent
  extends AppComponentBase
  implements OnInit {
  @ViewChild("dataTable") dataTable: Table;
  @ViewChild("paginator") paginator: Paginator;

  public startDate: moment.Moment = moment().startOf("day");
  public endDate: moment.Moment = moment().endOf("day");
  advancedFiltersAreShown = false;
  loading: boolean;
  isReceived = true;
  isCompleted = false;
  type = 1;
  filterText = "";
  tabs: MenuItem[];

  constructor(
    injector: Injector,
    private _pipelineService: PipelineServiceProxy,
    private _teamTaskService: TeamGroupTaskServiceProxy
  ) {
    super(injector);
  }

  ngOnInit() {
    this.getTabs();
    this.loading = true;
  }
  getModels(event?: LazyLoadEvent) {
    //this.loading = true;
    this.primengTableHelper.showLoadingIndicator();
    this._teamTaskService
      .getGPipelines(
        this.startDate,
        this.endDate,
        this.type,
        this.filterText,
        this.primengTableHelper.getSorting(this.dataTable),
        this.primengTableHelper.getMaxResultCount(this.paginator, event),
        this.primengTableHelper.getSkipCount(this.paginator, event)
      )
      .subscribe((result) => {
        console.log(result);
        this.primengTableHelper.totalRecordsCount = result.totalCount;
        this.primengTableHelper.records = result.items;
        this.primengTableHelper.hideLoadingIndicator();
      });
  }

  getTabs() {
    this.tabs = [
      { label: "已分解", icon: "fa fa-fw fa-bar-chart" },
      { label: "未分解", icon: "fa fa-fw fa-calendar" },
    ];
  }
  tabTypeClick(tab: any) {
    this.isCompleted = false;
    if (tab == "已分解") {
      this.type = 1;
    } else if (tab == "未分解") {
      this.type = 2;
    }
    this.getModels();
  }
}
